package cn.jinbyte.starter.data.autoconfigure;

import cn.jinbyte.data.service.CacheService;
import cn.jinbyte.data.service.Sm2Service;
import cn.jinbyte.starter.data.config.DataProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
@RequiredArgsConstructor
@EnableConfigurationProperties(DataProperties.class)
public class DataAutoConfiguration {

    /**
     * 创建sm2服务
     *
     * @param cacheService   缓存服务
     * @param dataProperties 数据配置
     * @return cn.jinbyte.data.service.Sm2Service
     */
    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnBean(CacheService.class)
    public Sm2Service sm2Service(CacheService<String> cacheService, DataProperties dataProperties) {
        return new Sm2Service(cacheService, dataProperties.getCrypt());
    }
}
